package com.ckx.controller;

import com.ckx.domain.ResponseResult;
import com.ckx.domain.dto.LinkDto;
import com.ckx.domain.entity.Link;
import com.ckx.domain.vo.LinkVo;
import com.ckx.domain.vo.PageVo;
import com.ckx.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, Link link){
        PageVo pageVo = linkService.listByPage(pageNum, pageSize, link);
        return ResponseResult.okResult(pageVo);
    }

    @PostMapping
    public ResponseResult addLink(@RequestBody LinkDto linkDto){
        linkService.addLink(linkDto);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{ids}")
    public ResponseResult delLing(@PathVariable @RequestBody List<Long> ids){
        linkService.del4DelFlag(ids);
        return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    public ResponseResult getLinkInfo(@PathVariable Long id){
        LinkVo linkVo = linkService.getLinkInfo(id);
        return ResponseResult.okResult(linkVo);
    }

    @PutMapping
    public ResponseResult updateLink(@RequestBody LinkDto linkDto){
        linkService.updateLink(linkDto);
        return ResponseResult.okResult();
    }

    @PutMapping("/changeLinkStatus")
    public ResponseResult changeLinkStatus(@RequestBody LinkDto linkDto){
        linkService.changeLinkStatus(linkDto);
        return ResponseResult.okResult();
    }

}
